552B - Vanya and Books - CodeForces Solution


implementation math *1200

Please click on ads to support us..

Python Code:

n=int(input())
 
i=1
count=0
 
while(i<=n):
    count+=n-i+1
    i*=10
 
print(count)

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define coutyes cout<<"YES\n"
#define coutno cout<<"NO\n"
#define endl "\n"

using namespace std;

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i * i <= n; i++) 
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

void solve()
{
    ll n;
    cin>>n;
    ll x = n,cnt=0;
    while (x)
    {
        x /= 10;
        cnt++;
    }
    ll ans=0;
    ans=n*cnt+cnt-1;
    ll y=1;
    for (int i = 0; i < cnt-1; ++i)
    {
        y*=10;
        ans-=y;
    }
    cout<<ans<<endl;

}

int main()
{
    fast_io;
    ll t;
    t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House